package svc

import (
	"app-user/rpc/internal/config"
	"fmt"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
)

func initDB(c config.Config) sqlx.SqlConn {
	switch c.DataBase.Driver {
	case "mysql":
		return initMySQL(c)
	default:
		return initMySQL(c)
	}
}

func initMySQL(c config.Config) sqlx.SqlConn {
	// root:12345678@tcp(127.0.0.1:3306)/tiktok?charset=utf8mb4&parseTime=True&loc=Local
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local",
		c.DataBase.User, c.DataBase.Pass, c.DataBase.Host, c.DataBase.Port, c.DataBase.DB)
	conn := sqlx.NewMysql(dsn)
	return conn
}
